<template>
  <div class="mobile-user">
    <!-- 顶部导航栏 -->
    <div class="mobile-nav-bar">
      <div class="nav-left" @click="goBack">
        <el-icon><ArrowLeft /></el-icon>
      </div>
      <div class="nav-title">个人中心</div>
      <div class="nav-right"></div>
    </div>

    <!-- 用户信息区域 -->
    <div class="user-info-card">
      <div class="user-avatar">
        <el-avatar :size="64" :icon="UserFilled" />
      </div>
      <div class="user-details">
        <div class="user-name">{{ userInfo.username || '未登录' }}</div>
        <div class="user-id">ID: {{ userInfo.id || '---' }}</div>
      </div>
    </div>

    <!-- 功能模块列表 -->
    <div class="function-list">
      <div class="function-group">
        <div class="function-title">账户管理</div>
        <div class="function-item" @click="handleEditProfile">
          <div class="item-icon">
            <el-icon><EditPen /></el-icon>
          </div>
          <div class="item-text">个人信息编辑</div>
          <div class="item-arrow">
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
        <div class="function-item" @click="handleChangePassword">
          <div class="item-icon">
            <el-icon><Lock /></el-icon>
          </div>
          <div class="item-text">修改密码</div>
          <div class="item-arrow">
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
      </div>

      <div class="function-group">
        <div class="function-title">观影管理</div>
        <div class="function-item" @click="handleFavorites">
          <div class="item-icon">
            <el-icon><Star /></el-icon>
          </div>
          <div class="item-text">我的收藏</div>
          <div class="item-arrow">
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
        <div class="function-item" @click="handleHistory">
          <div class="item-icon">
            <el-icon><VideoPlay /></el-icon>
          </div>
          <div class="item-text">观影历史</div>
          <div class="item-arrow">
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
      </div>

      <div class="function-group">
        <div class="function-title">其他设置</div>
        <div class="function-item" @click="handleAbout">
          <div class="item-icon">
            <el-icon><InfoFilled /></el-icon>
          </div>
          <div class="item-text">关于我们</div>
          <div class="item-arrow">
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
        <div class="function-item" @click="handleFeedback">
          <div class="item-icon">
            <el-icon><ChatDotRound /></el-icon>
          </div>
          <div class="item-text">意见反馈</div>
          <div class="item-arrow">
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
      </div>
    </div>

    <!-- 退出登录按钮 -->
    <div class="logout-button-container">
      <el-button type="danger" class="logout-button" @click="handleLogout">退出登录</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
import {
  ArrowLeft,
  UserFilled,
  EditPen,
  Lock,
  Star,
  VideoPlay,
  InfoFilled,
  ChatDotRound,
  ArrowRight
} from '@element-plus/icons-vue';

const router = useRouter();
const userInfo = ref({
  id: localStorage.getItem('id') || '',
  username: localStorage.getItem('name') || ''
});

// 返回上一页
const goBack = () => {
  router.back();
};

// 个人信息编辑
const handleEditProfile = () => {
  ElMessage.info('个人信息编辑功能即将上线');
};

// 修改密码
const handleChangePassword = () => {
  ElMessage.info('修改密码功能即将上线');
};

// 我的收藏
const handleFavorites = () => {
  ElMessage.info('收藏功能即将上线');
};

// 观影历史
const handleHistory = () => {
  ElMessage.info('观影历史功能即将上线');
};

// 关于我们
const handleAbout = () => {
  ElMessage.info('关于我们功能即将上线');
};

// 意见反馈
const handleFeedback = () => {
  ElMessage.info('意见反馈功能即将上线');
};

// 退出登录
const handleLogout = () => {
  ElMessageBox.confirm('确定要退出登录吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    // 清除本地存储的用户信息
    localStorage.removeItem('TOKEN');
    localStorage.removeItem('id');
    localStorage.removeItem('username');
    
    // 跳转到登录页
    router.push('/mobile/login');
    ElMessage.success('已退出登录');
  }).catch(() => {
    // 取消退出
  });
};

onMounted(() => {
  // 检查用户是否已登录
  const token = localStorage.getItem('TOKEN');
  if (!token) {
    ElMessage.warning('请先登录');
    router.push('/mobile/login');
  }
});
</script>

<style scoped lang="scss">
.mobile-user {
  min-height: 100vh;
  background-color: #f5f5f5;
  padding-bottom: 20px;
}

.mobile-nav-bar {
  display: flex;
  align-items: center;
  height: 50px;
  background-color: #fff;
  padding: 0 15px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.05);
  
  .nav-left {
    width: 24px;
    font-size: 20px;
  }
  
  .nav-title {
    flex: 1;
    text-align: center;
    font-size: 18px;
    font-weight: 500;
  }
  
  .nav-right {
    width: 24px;
  }
}

.user-info-card {
  margin: 15px;
  background-color: #fff;
  border-radius: 10px;
  padding: 20px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  
  .user-avatar {
    margin-right: 15px;
  }
  
  .user-details {
    .user-name {
      font-size: 18px;
      font-weight: 500;
      margin-bottom: 5px;
    }
    
    .user-id {
      font-size: 14px;
      color: #909399;
    }
  }
}

.function-list {
  margin: 15px;
}

.function-group {
  background-color: #fff;
  border-radius: 10px;
  margin-bottom: 15px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  
  .function-title {
    padding: 12px 15px;
    font-size: 16px;
    font-weight: 500;
    color: #303133;
    border-bottom: 1px solid #f0f0f0;
  }
  
  .function-item {
    display: flex;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid #f0f0f0;
    
    &:last-child {
      border-bottom: none;
    }
    
    .item-icon {
      width: 24px;
      height: 24px;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 10px;
      color: #ff6b6b;
      
      .el-icon {
        font-size: 18px;
      }
    }
    
    .item-text {
      flex: 1;
      font-size: 15px;
      color: #303133;
    }
    
    .item-arrow {
      color: #c0c4cc;
      
      .el-icon {
        font-size: 16px;
      }
    }
  }
}

.logout-button-container {
  margin: 30px 15px;
  
  .logout-button {
    width: 100%;
    height: 44px;
    font-size: 16px;
    border-radius: 22px;
  }
}
</style>